package com.tvunetworks.center.user.util;

import com.tvunetworks.center.common.constant.LocalConstant;
import com.tvunetworks.center.gs.model.Device;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.Comparator;

/**
 * @program: tvucc-user
 * @description:
 * @author lebronchen
 * @create: 2019-03-20 10:29
 **/
public class DeviceCompareOnlineFirst implements Serializable, Comparator<Device>  {


    @Override
    public int compare(Device o1, Device o2) {
        String status1 = o1.getStatus();
        String status2 = o2.getStatus();
        if (StringUtils.equals(status1, LocalConstant.DeviceStatus.ONLINE)) {
            status1 = "3";
        }
        if (StringUtils.equals(status2, LocalConstant.DeviceStatus.ONLINE)) {
            status2 = "3";
        }
        if (StringUtils.equals(status1, status2)) {
            return o1.getName().compareTo(o2.getName());
        }
        return status2.compareTo(status1);
    }
}
